<?php


namespace App\Http\Controllers\Api;

use App\Models\User;
use App\Utils\Code;
use App\Http\Controllers\Controller;
use App\Services\UserService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;


class UserController extends Controller
{

    /**
     * @api {post} api/login 登录
     */
    public function login(Request $request, UserService $service) {
        return $service->login($request->input(), true);
    }
    
    /**
     * @api {post} api/logout 退出登录
     */
    public function logout(Request $request, UserService $service) {
        return $service->logout($request->input(), true);
    }

    /**
     * @api {post} api/user/store 创建用户
     */
    public function store(Request $request, UserService $service) {
        return $service->store($request->input(), true);
    }

    /**
     * @api {get} api/user/info/{id} 用户信息
     */
    public function show(UserService $service, $id = null) {
        return $service->show($id);
    }

    /**
     * @api {post} api/user/update/{id} 更新用户
     */
    public function update(Request $request, UserService $service, $id = null) {
        return $service->update($id, $request->input());
    }

    /**
     * @api {delete} api/user/destroy/{id} 删除用户
     */
    public function destroy(UserService $service, $id){
        return $service->destroy($id);
    }

    /**
     * @api {get} api/user/paginate 用户分页
     */
    public function index(Request $request, UserService $service) {
        return $service->index($request->query());
    }

    /**
     * @api {get} api/user/menus 用户菜单
     */
    public function menus(Request $request, UserService $service) {
        return $service->menus($request->query());
    }
}
